package com.dpiinc.TechPage.pen.dialog

import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.dpiinc.TechPage.AIWriteSettings
import com.dpiinc.TechPage.R
import com.beiji.lib.pen.PenManager

/**
 * 低电量弹框
 * Created by X on 2018/7/4.
 */
class LowBatteryDialog(context: Context?, private var percent: Int) : BaseFloatDialog(context) {

    companion object {
        //低电量阈值
        private const val BATTERY_LEVEL_LOW_VALUE = PenManager.BATTERY_LEVEL_LOW_VALUE

        @JvmStatic
        fun reset() {
            AIWriteSettings.setLowBatteryDialogShowed(false)
        }

        @JvmStatic
        fun show(percent: Int, context: Context) {
            if (AIWriteSettings.hasLowBatteryDialogShowed()) {
                return
            }
            if (percent > BATTERY_LEVEL_LOW_VALUE) {
                return
            }
            val dialog = LowBatteryDialog(context, percent)
            dialog.show()
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.low_battery_dialog_layout)
    }

    override fun show() {
        super.show()
        AIWriteSettings.setLowBatteryDialogShowed(true)
        val msg = context.getString(R.string.low_battery_dialog_message_2, percent)
        val btnOK = findViewById<View>(R.id.btn_ok)
        val message = findViewById<TextView>(R.id.tv_message)
        message.text = msg
        btnOK.setOnClickListener {
            dismiss()
        }
    }

}
